package com.jy.rhin.facade.infra.controller.notification;

import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.infra.NotificationApplicationService;
import com.jy.rhin.infra.repo.notfication.participant.query.ParticipantQueryHandler;
import com.jy.rhin.sdk.dto.notification.EditSubscriberDto;
import com.jy.rhin.sdk.dto.notification.SubscriberDto;
import com.jy.rhin.sdk.dto.notification.SubscriberShortDto;
import com.jy.rhin.sdk.dto.notification.req.PublisherOrSubscriberReqDto;
import com.jy.rhin.sdk.feign.client.SubscriberFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dhl
 * @date 2022/6/29
 * @Description
 */
@RestController
@RequestMapping("/infra/notification/subscriber")
@Api(tags = "事件总线api", value = "订阅者管理api")
@Slf4j
public class SubscriberController implements SubscriberFeign {

    @Resource
    private ParticipantQueryHandler participantQueryHandler;
    @Resource
    NotificationApplicationService notificationApplicationService;

    @Override
    @ApiOperation("订阅者管理api-订阅者分页查询")
    @GetMapping("/querySubscriberPage")
    public Result<Page<SubscriberDto>> querySubscriberPage(PublisherOrSubscriberReqDto req) {
        return Result.success(participantQueryHandler.querySubscriberPage(req));
    }

    @Override
    @ApiOperation("订阅者管理api-订阅者列表查询")
    @GetMapping("/querySubscriberList")
    public Result<List<SubscriberShortDto>> querySubscriberList() {
        return Result.success(participantQueryHandler.querySubscriberList());
    }

    @Override
    @ApiOperation("订阅者管理api-订阅者编辑")
    @PostMapping("/editSubscriber")
    public Result<Long> editSubscriber(@RequestBody EditSubscriberDto dto) {
        return Result.success(notificationApplicationService.editSubscriber(dto));
    }

}
